﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace _02_Threads
{
    class Program
    {
        static void Thread1()
        {
            Thread.Sleep(2000);
            Console.WriteLine("Thread works, id: {0}", Thread.CurrentThread.ManagedThreadId);
        }

        static void Thread2(object obj)
        {
            try
            {
                while (true)
                {
                    Console.WriteLine("Thread works, id: {0}; obj: {1}", Thread.CurrentThread.ManagedThreadId, obj);
                    Thread.Sleep(100);
                }
            }catch(ThreadAbortException exception)
            {
                Console.WriteLine("ThreadAbortException!!!");
                //Thread.ResetAbort();
            }


            while (true)
            {
                Console.WriteLine("Thread works, again, id: {0}; obj: {1}", Thread.CurrentThread.ManagedThreadId, obj);
                Thread.Sleep(100);
            }
        }

        static void Main(string[] args)
        {
            Thread thread = new Thread(Thread1);
            thread.IsBackground = true;
            thread.Start();

            thread.Join();


            //Thread thread = new Thread(new ParameterizedThreadStart(Thread2));
            //Console.WriteLine("=============Start============");            

            //thread.Start("hello");

            //Thread.Sleep(2000);
            //Console.WriteLine("=============suspend============");            
            //thread.Suspend();
            //Thread.Sleep(2000);
            //Console.WriteLine("=============Resume============");
            //thread.Resume();

            //Thread.Sleep(2000);
            //Console.WriteLine("=============Abort============");

            //thread.Abort();

        }
    }
}
